<?php

namespace app\index\model;

use think\Model;
use think\model\concern\SoftDelete;

class CommentReplyModel extends Model
{
    use SoftDelete;
    protected $name = 'car_comment_reply'; //表名      默认类型
    protected $autoWriteTimestamp = true;
    // 定义时间戳字段名
    protected $dateFormat = 'Y/m/d H:i:s';
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';
    protected $deleteTime='delete_at';

    public function userInfo()
    {
        return $this->hasOne(UserModel::class, 'id', 'userId')->field(['id', 'avatar', 'rank', 'nickname', 'comment_bg_id']);
    }

    public function like() {
        return $this->hasOne(CommentLike::class, 'relevancyId', 'id')->where('type', 2);
    }

    public function fatherInfo()
    {
        return $this->hasOne(CommentReplyModel::class, 'id', 'fatherid');
    }

    public function likeNum() {
        return $this->hasOne(CommentLike::class, 'relevancyId', 'id')->where('type', 2);
    }

    public function fatherUserInfo()
    {
        return $this->hasOne(UserModel::class, 'id', 'fatherUserId')->field(['id', 'avatar', 'rank', 'nickname', 'comment_bg_id']);
    }

    public function info()
    {
        return $this->hasOne(CommentModel::class, 'id', 'commentId')->with('resource')->bind([
            'photo_id',
            'photo_name',
            'cover'
        ]);
    }
}